import { BrowserRouter as Router, Route, Redirect } from 'react-router-dom'
// 导入组件
import Layout from './pages/layout'
import Login from './pages/login'
import { getToken } from '@/utils/auth.js'
import AuthRoute from '@/components/AuthRoute'
export default function App() {
  return (
    <Router>
      {/* 路由重定向 */}
      <Route
        path="/"
        exact
        render={() => <Redirect to="/home"></Redirect>}
      ></Route>
      <Route
        path="/login"
        render={() => {
          // 已经登陆就返回首页
          if (getToken()) {
            return <Redirect to="/home"></Redirect>
          } else {
            return <Login></Login>
          }
        }}
      ></Route>
      {/* <Route path="/home" component={Layout}></Route> */}
      <AuthRoute path="/home" component={Layout}></AuthRoute>
    </Router>
  )
}
